package com.javafactroy.kunlong.metadata;

import com.javafactroy.kunlong.DbAgent;
import com.javafactroy.kunlong.base.model.ReturnPageInfo;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import com.javafactroy.kunlong.data.entity.SysDictTypeApiEntity;
import com.javafactroy.kunlong.data.service.SysDictTypeService;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;
import org.junit.jupiter.api.*;


/**
*  @author raymond.lei@163.com
*  @date   2023-11-27 17:25:34

*/

@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
@SpringBootTest(classes = {DbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class SysDictTypeTestService {


    @Autowired
    SysDictTypeService service;

    String pkeyField = "dict_id";
    String pkeyProp = "dictId";

    public SysDictTypeApiEntity mock() {
        MockConfig mockConfig = new MockConfig()
                .doubleRange(1e-9d, 11112222.99999d)
                .floatRange(1e-8f, 11111112.99999f)
                .decimalScale(52).excludes(pkeyProp, "orderBys", "pageNum" , "pageSize")
                .subConfig("status").sizeRange(1,1).stringSeed("0", "1").globalConfig();
        SysDictTypeApiEntity entity = JMockData.mock(SysDictTypeApiEntity.class, mockConfig);
        log.info("mock entity = {}", CommonUtils.toJSONString(entity));
        return entity;
    }

    @BeforeEach
    void setUp() {
        log.info("setUp{}", "...");
    }

    @AfterEach
    void tearDown() {
        log.info("tearDown{}", "...");
    }


    @Test
    public void test001_query() {
        //save();
        SysDictTypeApiEntity  param = new SysDictTypeApiEntity() ;
        param.setPageSize(4).ge(pkeyField, 1);

        // param.like("mobileNo", "186");
        // param.notBetween("id", "1");
        // param.eq("opBy",-1);
        param.orderBy(pkeyField, "desc");

        ReturnPageInfo<SysDictTypeApiEntity> pageInfo = service.query(param);
        log.info("query pageInfo = {}", CommonUtils.toJSONString(pageInfo));

    }

    @Test
    public void test002_selectByPkey() {
        SysDictTypeApiEntity entity = service.selectByPkey(1l);
        log.info("selectByPkey entity = {}", entity);

    }

    @Test
    public void test003_save() {

        SysDictTypeApiEntity entity = mock();
        //service.save(entity.setShopName("122").setContact("ddl"));

        service.save(entity);
        log.info("save entity = {}", entity);

    }

    @Test
    public void test004_updateNotNull() {

        SysDictTypeApiEntity e = save();

        SysDictTypeApiEntity entity = new  SysDictTypeApiEntity();
        entity.setDictId(e.getDictId());

        service.updateNotNull(entity);
        log.info("save entity = {}", entity);

    }

   SysDictTypeApiEntity save() {
        SysDictTypeApiEntity entity = mock();
        service.save(entity);
        return entity;
    }

}

